package com.sinping.qh.query.lab;

import com.sinping.qh.query.base.Operator;
import com.sinping.qh.query.base.QueryParams;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 单位列表查询
 *
 * @author Tiansx
 * @create 2018-05-30 14:39
 **/
@Data
public class UnitQuery implements QueryParams ,Serializable {
    private static final long serialVersionUID = 47671777260743261L;
    static Map<String, String> aliasMap = new HashMap<>();
    static Map<String, Operator> operatorMap = new HashMap<>();

    /**
     * 单位名称
     */
    private String unitName;
    /**
     * 单位类型
     */
    private String unitType;
    private String status;
    /**
     * 用在app(根据用户id,获取用户负责的院系列表接口)
     */
    private List<String> unitIDList;

    static {
        aliasMap.put("unitIDList", "_id");
        aliasMap.put("unitName", "unit_name");
        aliasMap.put("unitType", "unit_type");
        aliasMap.put("status","status");

        operatorMap.put("unitName", Operator.regex);
        operatorMap.put("unitType", Operator.eq);
        operatorMap.put("status",Operator.eq);
        operatorMap.put("unitIDList",Operator.in);
    }

    @Override
    public String getAlias(String fieldName) {
        return aliasMap.getOrDefault(fieldName, fieldName);
    }

    @Override
    public Operator getOperators(String fieldName) {
        return operatorMap.getOrDefault(fieldName, Operator.eq);
    }
}
